/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import {
  Form, Input, Radio, Select, Icon,
  DatePicker, TreeSelect, Divider,
} from 'antd';
import {connect} from 'dva';
import moment from 'moment'
import request from '@/utils/request';
const FormItem = Form.Item;
const { TextArea } = Input;
const RadioGroup = Radio.Group;
const Option = Select.Option;
const TreeNode = TreeSelect.TreeNode;
@connect(({ inner_address_book, loading, global }) => ({
  inner_address_book,
  global,
  loading: loading.models.inner_address_book,
}))
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      fileList:[]
    };
  }

  componentDidMount() {
  }
  renderTreeNodes = data =>
    data.map((item,index) => {

      if (item.children.length>0) {
        return (
          <TreeNode value={item.id} title={item.name} key={item.id+index} >
            {this.renderTreeNodes(item.children)}
          </TreeNode>
        );
      }
      return <TreeNode  value={item.id}   key={item.id+index}  title={item.name}  />;
    });
  render() {
    const {
      inner_address_book: { organizationData,loading, tableY, meta, searchParams, selectedRowKeys },
    } = this.props;
    console.log('organizationData',organizationData)
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 6},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;
    const props = {
      onRemove: (file) => {
        this.setState(({ fileList }) => {
          const index = fileList.indexOf(file);
          const newFileList = fileList.slice();
          newFileList.splice(index, 1);
          return {
            fileList: newFileList,
          };
        });
      },
      beforeUpload: (file) => {
        this.setState(({ fileList }) => ({
          fileList: [file],
        }));
        return false;
      },
      fileList: this.state.fileList,
    };
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               原部门
            </span>
            )}
          >
            {getFieldDecorator('origin_structure_name', {
              initialValue: this.props.editRecord?this.props.editRecord.department_name:'',
            })(
              <Input disabled={true}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               原职位
            </span>
            )}
          >
            {getFieldDecorator('origin_position', {
              initialValue: this.props.editRecord?this.props.editRecord.position:'',
            })(
              <Input disabled={true}/>
            )}
          </FormItem>
          <Divider style={{marginBottom:'20px'}}></Divider>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               新部门
            </span>
            )}
          >
            {getFieldDecorator('department_id', {
              initialValue: this.props.editRecord?this.props.editRecord.department_id:'',
              rules: [{ required: true, message: '请选择部门' }],
            })(
              <TreeSelect
                treeDefaultExpandAll
                allowClear
                dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
              >
                {this.renderTreeNodes(organizationData)}
              </TreeSelect>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               新职位
            </span>
            )}
          >
            {getFieldDecorator('position', {
              initialValue: this.props.editRecord?this.props.editRecord.position:'',
              rules: [{ required: true, message: '' }],
            })(
              <Input />
            )}
          </FormItem>
        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default AddPoliciesFormWrap;


